/************************************************************************/
/*Copyright (c) James Zhao 2007,2008
/*This file is part of AdminOverlay.
/*AdminOverlay is free software: you can redistribute it and/or modify
/*it under the terms of the GNU General Public License as published by
/*the Free Software Foundation, either version 3 of the License, or
/*(at your option) any later version.
/*
/*AdminOverlay is distributed in the hope that it will be useful,
/*but WITHOUT ANY WARRANTY; without even the implied warranty of
/*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/*GNU General Public License for more details.
/*
/*You should have received a copy of the GNU General Public License
/*along with Foobar.  If not, see <http://www.gnu.org/licenses/>.                                                                     */
/*************************************************************************/
#include "UIPanel.h"
#include "GraphicsAdapter.h"
DWORD UIPanel::topColor = 0xFFCCCCCC;
DWORD UIPanel::bottomColor = 0xFFCCCCCC;

UIPanel::UIPanel( int x, int y, int width, int height ) :  UIControl(x, y, width, height)
{
	isCenterAligned = false;
	doDraw = true;
	background = new QuadVisual(x, y, width, height, 
		topColor, bottomColor);	
}
UIPanel::~UIPanel(void)
{
	delete background;
}
void UIPanel::draw(LPDIRECT3DDEVICE9 device) 
{
	if(hasBoundsChanged)
	{
		background->X(globalPos.x());
		background->Y(globalPos.y());
		background->Width(width);
		background->Height(height);
		hasBoundsChanged = false;
	}
		//draw code
	background->draw(device);
	UIControl::draw(device);

}

void UIPanel::onDeviceReset()
{
	background->onDeviceReset();
	UIControl::onDeviceReset();
}


void UIPanel::layout( QPoint pt )
{
	UIControl::layout(pt);
	if(parent != NULL)
	{
		if(isCenterAligned)
		{
			GlobalX(parent->X() + parent->Width() / 2 - Width() / 2);
		}
	}	
}

void UIPanel::onBoundsChanged()
{
	UIControl::onBoundsChanged();
	background->X(GlobalPos().x());
	background->Y(GlobalPos().y());
	background->Width(width);
	background->Height(height);
	hasBoundsChanged = true;
}

void UIPanel::TopColor( DWORD val )
{
	topColor = val;
	background->TopLeftColor(val);
	background->TopRightColor(val);
}

DWORD UIPanel::TopColor() const
{
	return topColor;
}

void UIPanel::BottomColor( DWORD val )
{
	bottomColor = val;
	background->BottomLeftColor(val);
	background->BottomRightColor(val);
}

DWORD UIPanel::BottomColor() const
{
	return bottomColor;
}